import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * permissionService - 数据权限service
 * @date: 2018-7-24

 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
var tenantId = getCurrentOrganizationId();

function relApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/permission-rel") : "permission-rel";
}
/**
 * 屏蔽范围列表
 * @async
 * @function queryRangeList
 * @param {object} params - 查询条件
 * @returns {object} fetch Promise
 */


export function queryRangeList() {
  return _queryRangeList.apply(this, arguments);
}
/**
 * 屏蔽范围列表 - 租户级
 * @async
 * @function queryOrganizationRangeList
 * @param {object} params - 查询条件
 * @param {!number} organizationId - 组织ID
 * @returns {object} fetch Promise
 */

function _queryRangeList() {
  _queryRangeList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var params,
        _args = arguments;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/permission-ranges"), {
              query: params
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryRangeList.apply(this, arguments);
}

export function queryOrganizationRangeList() {
  return _queryOrganizationRangeList.apply(this, arguments);
}
/**
 * 屏蔽规则列表
 * @async
 * @function queryRuleList
 * @param {object} params - 查询条件
 * @returns {object} fetch Promise
 */

function _queryOrganizationRangeList() {
  _queryOrganizationRangeList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    var params,
        organizationId,
        _args2 = arguments;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
            organizationId = _args2.length > 1 ? _args2[1] : undefined;
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/permission-ranges"), {
              query: params
            }));

          case 3:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryOrganizationRangeList.apply(this, arguments);
}

export function queryRuleList() {
  return _queryRuleList.apply(this, arguments);
}
/**
 * 屏蔽规则列表 - 租户级
 * @async
 * @function queryOrganizationRuleList
 * @param {object} params - 查询条件
 * @param {!number} organizationId - 组织ID
 * @returns {object} fetch Promise
 */

function _queryRuleList() {
  _queryRuleList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
    var params,
        _args3 = arguments;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            params = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/permission-rules"), {
              query: params
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryRuleList.apply(this, arguments);
}

export function queryOrganizationRuleList() {
  return _queryOrganizationRuleList.apply(this, arguments);
}
/**
 * 查询值集
 * @async
 * @function queryCode
 * @param {object} params - 查询条件
 * @param {!string} param.lovCode - 查询条件
 * @returns {object} fetch Promise
 */

function _queryOrganizationRuleList() {
  _queryOrganizationRuleList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
    var params,
        organizationId,
        _args4 = arguments;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            params = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
            organizationId = _args4.length > 1 ? _args4[1] : undefined;
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/permission-rules"), {
              query: params
            }));

          case 3:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _queryOrganizationRuleList.apply(this, arguments);
}

export function queryCode() {
  return _queryCode.apply(this, arguments);
}
/**
 * 创建屏蔽规则
 * @async
 * @function createRule
 * @param {object} data - 数据
 * @returns {object} fetch Promise
 */

function _queryCode() {
  _queryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
    var params,
        _args5 = arguments;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            params = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/lovs/value"), {
              query: params
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryCode.apply(this, arguments);
}

export function createRule() {
  return _createRule.apply(this, arguments);
}
/**
 * 创建屏蔽规则 - 租户级
 * @async
 * @function createOrganizationRule
 * @param {object} data - 数据
 * @param {!number} organizationId - 组织ID
 * @returns {object} fetch Promise
 */

function _createRule() {
  _createRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
    var data,
        _args6 = arguments;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            data = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/permission-rules"), {
              method: 'POST',
              body: data
            }));

          case 2:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _createRule.apply(this, arguments);
}

export function createOrganizationRule() {
  return _createOrganizationRule.apply(this, arguments);
}
/**
 * 修改屏蔽规则
 * @async
 * @function updateRule
 * @param {object} data - 数据
 * @returns {object} fetch Promise
 */

function _createOrganizationRule() {
  _createOrganizationRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
    var data,
        organizationId,
        _args7 = arguments;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            data = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
            organizationId = _args7.length > 1 ? _args7[1] : undefined;
            return _context7.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/permission-rules"), {
              method: 'POST',
              body: data
            }));

          case 3:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _createOrganizationRule.apply(this, arguments);
}

export function updateRule() {
  return _updateRule.apply(this, arguments);
}
/**
 * 修改屏蔽规则 - 租户级
 * @async
 * @function updateOrganizationRule
 * @param {object} data - 数据
 * @param {!number} organizationId - 组织ID
 * @returns {object} fetch Promise
 */

function _updateRule() {
  _updateRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
    var data,
        _args8 = arguments;
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            data = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
            return _context8.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/permission-rules"), {
              method: 'PUT',
              body: data
            }));

          case 2:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _updateRule.apply(this, arguments);
}

export function updateOrganizationRule() {
  return _updateOrganizationRule.apply(this, arguments);
}
/**
 * 删除屏蔽规则
 * @async
 * @function delete
 * @param {object} data - 数据
 * @returns {object} fetch Promise
 */

function _updateOrganizationRule() {
  _updateOrganizationRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
    var data,
        organizationId,
        _args9 = arguments;
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            data = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
            organizationId = _args9.length > 1 ? _args9[1] : undefined;
            return _context9.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/permission-rules"), {
              method: 'PUT',
              body: data
            }));

          case 3:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _updateOrganizationRule.apply(this, arguments);
}

export function deleteRule(_x) {
  return _deleteRule.apply(this, arguments);
}
/**
 * 删除屏蔽规则 - 租户级
 * @async
 * @function deleteOrganizationRule
 * @param {object} data - 数据
 * @param {!number} organizationId - 组织ID
 * @returns {object} fetch Promise
 */

function _deleteRule() {
  _deleteRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            return _context10.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/permission-rules"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _deleteRule.apply(this, arguments);
}

export function deleteOrganizationRule(_x2, _x3) {
  return _deleteOrganizationRule.apply(this, arguments);
}
/**
 * 创建屏蔽范围
 * @async
 * @function createRange
 * @param {object} data - 数据
 * @returns {object} fetch Promise
 */

function _deleteOrganizationRule() {
  _deleteOrganizationRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params, organizationId) {
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            return _context11.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/permission-rules"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _deleteOrganizationRule.apply(this, arguments);
}

export function createRange() {
  return _createRange.apply(this, arguments);
}
/**
 * 创建屏蔽范围 - 租户级
 * @async
 * @function createRange
 * @param {object} data - 数据
 * @returns {object} fetch Promise
 */

function _createRange() {
  _createRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
    var data,
        _args12 = arguments;
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            data = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
            return _context12.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/permission-ranges"), {
              method: 'POST',
              body: data
            }));

          case 2:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _createRange.apply(this, arguments);
}

export function createOrganizationRange() {
  return _createOrganizationRange.apply(this, arguments);
}
/**
 * 修改屏蔽范围
 * @async
 * @function updateRange
 * @param {object} data - 数据
 * @returns {object} fetch Promise
 */

function _createOrganizationRange() {
  _createOrganizationRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
    var data,
        organizationId,
        _args13 = arguments;
    return _regeneratorRuntime.wrap(function _callee13$(_context13) {
      while (1) {
        switch (_context13.prev = _context13.next) {
          case 0:
            data = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {};
            organizationId = _args13.length > 1 ? _args13[1] : undefined;
            return _context13.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/permission-ranges"), {
              method: 'POST',
              body: data
            }));

          case 3:
          case "end":
            return _context13.stop();
        }
      }
    }, _callee13);
  }));
  return _createOrganizationRange.apply(this, arguments);
}

export function updateRange() {
  return _updateRange.apply(this, arguments);
}
/**
 * 修改屏蔽范围 - 租户级
 * @async
 * @function updateOrganizationRange
 * @param {object} data - 数据
 * @returns {object} fetch Promise
 */

function _updateRange() {
  _updateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
    var data,
        _args14 = arguments;
    return _regeneratorRuntime.wrap(function _callee14$(_context14) {
      while (1) {
        switch (_context14.prev = _context14.next) {
          case 0:
            data = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
            return _context14.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/permission-ranges"), {
              method: 'PUT',
              body: data
            }));

          case 2:
          case "end":
            return _context14.stop();
        }
      }
    }, _callee14);
  }));
  return _updateRange.apply(this, arguments);
}

export function updateOrganizationRange() {
  return _updateOrganizationRange.apply(this, arguments);
}
/**
 * 删除屏蔽范围
 * @async
 * @function deleteRange
 * @param {number} rangeId - 屏蔽范围ID
 * @returns {object} fetch Promise
 */

function _updateOrganizationRange() {
  _updateOrganizationRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
    var data,
        organizationId,
        _args15 = arguments;
    return _regeneratorRuntime.wrap(function _callee15$(_context15) {
      while (1) {
        switch (_context15.prev = _context15.next) {
          case 0:
            data = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
            organizationId = _args15.length > 1 ? _args15[1] : undefined;
            return _context15.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/permission-ranges"), {
              method: 'PUT',
              body: data
            }));

          case 3:
          case "end":
            return _context15.stop();
        }
      }
    }, _callee15);
  }));
  return _updateOrganizationRange.apply(this, arguments);
}

export function deleteRange(_x4) {
  return _deleteRange.apply(this, arguments);
}
/**
 * 删除屏蔽范围
 * @async
 * @function deleteOrganizationRange
 * @param {number} rangeId - 屏蔽范围ID
 * @returns {object} fetch Promise
 */

function _deleteRange() {
  _deleteRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(params) {
    return _regeneratorRuntime.wrap(function _callee16$(_context16) {
      while (1) {
        switch (_context16.prev = _context16.next) {
          case 0:
            return _context16.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/permission-ranges"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context16.stop();
        }
      }
    }, _callee16);
  }));
  return _deleteRange.apply(this, arguments);
}

export function deleteOrganizationRange(_x5, _x6) {
  return _deleteOrganizationRange.apply(this, arguments);
}
/**
 * 创建屏蔽范围规则关系
 * @async
 * @function createRange
 * @param {object} data - 数据
 * @returns {object} fetch Promise
 */

function _deleteOrganizationRange() {
  _deleteOrganizationRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(params, organizationId) {
    return _regeneratorRuntime.wrap(function _callee17$(_context17) {
      while (1) {
        switch (_context17.prev = _context17.next) {
          case 0:
            return _context17.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/permission-ranges"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context17.stop();
        }
      }
    }, _callee17);
  }));
  return _deleteOrganizationRange.apply(this, arguments);
}

export function addPermissionRel() {
  return _addPermissionRel.apply(this, arguments);
}
/**
 * 屏蔽范围规则关系列表
 * @async
 * @function queryPermissionRel
 * @param {!number} rangeId - 数据
 * @returns {object} fetch Promise
 */

function _addPermissionRel() {
  _addPermissionRel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
    var data,
        _args18 = arguments;
    return _regeneratorRuntime.wrap(function _callee18$(_context18) {
      while (1) {
        switch (_context18.prev = _context18.next) {
          case 0:
            data = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {};
            return _context18.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(relApi()), {
              method: 'POST',
              body: data
            }));

          case 2:
          case "end":
            return _context18.stop();
        }
      }
    }, _callee18);
  }));
  return _addPermissionRel.apply(this, arguments);
}

export function queryPermissionRel(_x7) {
  return _queryPermissionRel.apply(this, arguments);
}
/**
 * 删除屏蔽范围规则关系
 * @async
 * @function deletePermissionRel
 * @param {!number} permissionRelId - 屏蔽范围规则关系ID
 * @returns {object} fetch Promise
 */

function _queryPermissionRel() {
  _queryPermissionRel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(rangeId) {
    return _regeneratorRuntime.wrap(function _callee19$(_context19) {
      while (1) {
        switch (_context19.prev = _context19.next) {
          case 0:
            return _context19.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(relApi(), "/").concat(rangeId)));

          case 1:
          case "end":
            return _context19.stop();
        }
      }
    }, _callee19);
  }));
  return _queryPermissionRel.apply(this, arguments);
}

export function deletePermissionRel(_x8) {
  return _deletePermissionRel.apply(this, arguments);
}

function _deletePermissionRel() {
  _deletePermissionRel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(params) {
    return _regeneratorRuntime.wrap(function _callee20$(_context20) {
      while (1) {
        switch (_context20.prev = _context20.next) {
          case 0:
            return _context20.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(relApi()), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context20.stop();
        }
      }
    }, _callee20);
  }));
  return _deletePermissionRel.apply(this, arguments);
}